package com.byb.server.service.impl;

import com.byb.server.service.WcClainPartyService;
import com.byb.server.domain.WcClainParty;
import com.byb.server.repository.WcClainPartyRepository;
import com.byb.server.repository.search.WcClainPartySearchRepository;
import com.byb.server.service.dto.WcClainPartyDTO;
import com.byb.server.service.mapper.WcClainPartyMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import static org.elasticsearch.index.query.QueryBuilders.*;

/**
 * Service Implementation for managing WcClainParty.
 */
@Service
@Transactional
public class WcClainPartyServiceImpl implements WcClainPartyService{

    private final Logger log = LoggerFactory.getLogger(WcClainPartyServiceImpl.class);

    private final WcClainPartyRepository wcClainPartyRepository;

    private final WcClainPartyMapper wcClainPartyMapper;

    private final WcClainPartySearchRepository wcClainPartySearchRepository;
    public WcClainPartyServiceImpl(WcClainPartyRepository wcClainPartyRepository, WcClainPartyMapper wcClainPartyMapper, WcClainPartySearchRepository wcClainPartySearchRepository) {
        this.wcClainPartyRepository = wcClainPartyRepository;
        this.wcClainPartyMapper = wcClainPartyMapper;
        this.wcClainPartySearchRepository = wcClainPartySearchRepository;
    }

    /**
     * Save a wcClainParty.
     *
     * @param wcClainPartyDTO the entity to save
     * @return the persisted entity
     */
    @Override
    public WcClainPartyDTO save(WcClainPartyDTO wcClainPartyDTO) {
        log.debug("Request to save WcClainParty : {}", wcClainPartyDTO);
        WcClainParty wcClainParty = wcClainPartyMapper.toEntity(wcClainPartyDTO);
        wcClainParty = wcClainPartyRepository.save(wcClainParty);
        WcClainPartyDTO result = wcClainPartyMapper.toDto(wcClainParty);
       // wcClainPartySearchRepository.save(wcClainParty);
        return result;
    }

    /**
     *  Get all the wcClainParties.
     *
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<WcClainPartyDTO> findAll(Pageable pageable) {
        log.debug("Request to get all WcClainParties");
        return wcClainPartyRepository.findAll(pageable)
            .map(wcClainPartyMapper::toDto);
    }

    /**
     *  Get one wcClainParty by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Override
    @Transactional(readOnly = true)
    public WcClainPartyDTO findOne(Long id) {
        log.debug("Request to get WcClainParty : {}", id);
        WcClainParty wcClainParty = wcClainPartyRepository.findOne(id);
        return wcClainPartyMapper.toDto(wcClainParty);
    }

    /**
     *  Delete the  wcClainParty by id.
     *
     *  @param id the id of the entity
     */
    @Override
    public void delete(Long id) {
        log.debug("Request to delete WcClainParty : {}", id);
        wcClainPartyRepository.delete(id);
        //wcClainPartySearchRepository.delete(id);
    }

    /**
     * Search for the wcClainParty corresponding to the query.
     *
     *  @param query the query of the search
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Override
    @Transactional(readOnly = true)
    public Page<WcClainPartyDTO> search(String query, Pageable pageable) {
        log.debug("Request to search for a page of WcClainParties for query {}", query);
        Page<WcClainParty> result = wcClainPartySearchRepository.search(queryStringQuery(query), pageable);
        return result.map(wcClainPartyMapper::toDto);
    }
}
